﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKSparseDistance.Properties;
using YJKRoomInspection.ProgramArchitecture;
using YJKRoomInspection.ShowDataForm;
using YArchitech.Controls;
using YJKRevitBase.WinForm;
using YJKInspectModelFunc;

namespace YJKSparseDistance.ControlLayer
{
	public class TempleCmd
	{
		public static ExternalCommandData ExternalCommandData
		{
			get
			{
				return TempleCmd.m_ExternalCommandData;
			}
			private set
			{
				TempleCmd.m_ExternalCommandData = value;
			}
		}

		public static IWin32Window RevitHandle
		{
			get
			{
				return TempleCmd.m_RevitHandle;
			}
			private set
			{
				TempleCmd.m_RevitHandle = value;
			}
		}

		public static List<Level> LstSelectLevel
		{
			get
			{
				return TempleCmd.m_lstSelectLevel;
			}
			private set
			{
				TempleCmd.m_lstSelectLevel = value;
			}
		}

		public void Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			try
			{
				TempleCmd.ExternalCommandData = null;
				TempleCmd.RevitHandle = null;
				TempleCmd.LstSelectLevel = null;
				UIApplication application = commandData.Application;
                Autodesk.Revit.ApplicationServices.Application application2 = application.Application;
				Document document = application.ActiveUIDocument.Document;
				EventUseMethod.CreatSchema(document, Resources.Str_GuidForEvacuation);
				TempleCmd.ExternalCommandData = commandData;
				TempleCmd.RevitHandle = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
				SelectFloorManager selectFloorManager = new SelectFloorManager();
				selectFloorManager.IfEvacuationDistance = true;
				List<Level> list = new List<Level>();
				bool flag = selectFloorManager.SelectFloorLevels(document, false);
				list = selectFloorManager.m_AllLevels;
				if (flag && list.Count != 0)
				{
					TempleCmd.LstSelectLevel = list;
                    YJKInspectModelFunc.Utility.AddRoomToNoneRoomPlace(document, list);
					new FrontRoomArch(application, new EvacuationDistanceArch(), TempleCmd.ExternalCommandData, TempleCmd.LstSelectLevel, TempleCmd.RevitHandle).IfNeedYJKRoomInspection(document, list);
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Show("出现错误" + ex.Message);
			}
			finally
			{
                YJKInspectModelFunc.Utility.DeleteAddRoom(TempleCmd.m_ExternalCommandData.Application.ActiveUIDocument.Document, PublicYJKRoomInspection.LstFrontRoomIds);
			}
		}

		private static ExternalCommandData m_ExternalCommandData;

		private static IWin32Window m_RevitHandle;

		private static List<Level> m_lstSelectLevel;
	}
}
